package com.thiny.android.app.tsms.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public abstract class BasicAdapter<T> extends BaseAdapter {
	private Context context;
	private List<T> list;

	public BasicAdapter(Context context, List<T> list) {
		this.context = context;
		this.list = list;
	}

	protected Context getContext() {
		return context;
	}

	protected List<T> getList() {
		return list;
	}
	
	protected LayoutInflater getInflater() {
		return LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		if (list == null) {
			return 0;
		}
		return list.size();
	}

	@Override
	public T getItem(int position) {
		if (list == null || list.isEmpty()) {
			return null;
		}
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public abstract View getView(int position, View convertView,
			ViewGroup parent);
}
